﻿using MVSDK;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MDVCamera
{
	public class EnumerateCameras
	{
		private static EnumerateCameras _instance = null;
		private static readonly object padlock = new object();
		private EnumerateCameras(){}
		public static EnumerateCameras Instance
		{
			get
			{
				if(_instance == null)
				{
					lock (padlock)
					{
						if (_instance == null) _instance = new EnumerateCameras();
					}
				}
				return _instance;
			}
		}

		private string ByteArray2String(byte[] bves)
		{
			string srtn = "";
			foreach(byte bv in bves)
			{
				if (bv == 0) return srtn;
				srtn += Convert.ToChar(bv);
			}
			return srtn;
		}
		public bool EnumCameraName(string name)
		{
			lock (this)
			{
				//tSdkCameraDevInfo[] devInfoes = null;
				MvApi.CameraEnumerateDeviceEx();
				//if (MvApi.CameraEnumerateDevice(out devInfoes) == CameraSdkStatus.CAMERA_STATUS_SUCCESS)
				//{
				//	if (-1 != Array.FindIndex(devInfoes, c => ByteArray2String(c.acFriendlyName) == name))
				//	{
				//		return true;
				//	}

				//	//for (int i = 0; i < devInfoes.Length; i++)
				//	//{
				//	//	string txt = "";
				//	//	txt += System.Text.Encoding.Default.GetString(devInfoes[i].acFriendlyName);
				//	//	txt += "," + ByteArray2String(devInfoes[i].acFriendlyName);
				//	//	System.Diagnostics.Debug.WriteLine(txt);
				//	//	//Array.Find(devInfoes, c => c.acProductName == name);
				//	//}
				//}
				return false;
			}
		}
	}
}
